package ar.com.jwa.services;
import java.io.IOException;
import java.util.Collection;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import org.springframework.beans.factory.annotation.Autowired;

import ar.com.jwa.domain.User;
import ar.com.jwa.domain.emailing.ConfirmationHtmlMail;


public class sendMailTestCase extends ServiceTestCase {

	@Autowired
	private UserLocalService userLocalService;
	
	@Autowired
	private ConfirmationHtmlMail dailyMail;
	
	public void testSendMail() throws IOException {
		
		Collection<User> players = this.userLocalService.findAll();
		
		dailyMail.setConfirmedPlayers(players);
		
		dailyMail.setSubject("Soccer Weekly");
		
		dailyMail.setTo("C_H_I_C_H_I_77@HOTMAIL.COM");
		
		dailyMail.setFrom("Soccer@Comunidad-Garmendia.com");
		
		dailyMail.setHost("smtp.gmail.com");		
		
		dailyMail.setProtocol("smtps");
		
		dailyMail.setSmtpUser("nicolas.hernan.gonzalez@gmail.com");
		
		dailyMail.setSmtpPassword("WANNABESEDEATED");
		
		try {
			
			dailyMail.send();
		
		} catch (AddressException e) {
			e.printStackTrace();
			fail(e.toString());
		
		} catch (MessagingException e) {
			e.printStackTrace();
			fail(e.toString());
		}
	}
	
	/**
	 * @return the userLocalService
	 */
	public UserLocalService getUserLocalService() {
		return userLocalService;
	}

	/**
	 * @param userLocalService the userLocalService to set
	 */
	public void setUserLocalService(UserLocalService userLocalService) {
		this.userLocalService = userLocalService;
	}

	/**
	 * @return the dailyMail
	 */
	public ConfirmationHtmlMail getDailyMail() {
		return dailyMail;
	}

	/**
	 * @param dailyMail the dailyMail to set
	 */
	public void setDailyMail(ConfirmationHtmlMail dailyMail) {
		this.dailyMail = dailyMail;
	}

}
